<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>后台管理系统</title>
	    <meta name="author" content="BaiYY"/>
	    <meta charset="utf-8">
	    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	    <meta name="renderer" content="webkit">
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/bootstrap.min.css"/>
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/Font/css/font-awesome.min.css"/>
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/index.css"/>
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/pages.css"/>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/jquery.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/page.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/bootstrap.min.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/index.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/time.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/pages.js"></script>
	</head>
	<body>
		<!--右边侧栏开始-->
		<div class="right-sidebar" style="max-width: 1200px;">
			<ul class="nav nav-tabs" style="margin-bottom: 16px" role="tablist">
				<li role="presentation" class="active"><a href="aUser.html">代理审核</a></li>
				<li role="presentation"><a href="agentUserList.html">代理列表</a></li>
				<li role="presentation"><a href="agentUserSearch.html">代理搜索</a></li>
				<li role="presentation"><a href="agentUserBuy.html">购买记录</a></li>
				<li role="presentation"><a href="agentUserSell.html">充值记录</a></li>
			</ul>
			<div class="admin_tab_cont" style="display:block;" id="tab1">
				<section class="table-responsive">
					<table class="table table-bordered">
						<thead>
							<tr>
								<th>代理ID</th>
								<th>手机号码</th>
								<th>真实姓名</th>
								<th>推荐码</th>
								<th>注册时间</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody id="dataList"></tbody>
					</table>
				</section>
				<div style="width: 100%;">
					<ul class="page" id="page" style="width: 100%;overflow: hidden;"></ul>
				</div>
			</div>
			<div id="bg-models">
				<div id="bg-contents">
					<i class="glyphicon glyphicon-remove" id="btn-closed"></i>
					<div class="title_dialog">系统提示！</div>
					<div class="discription_dialog">确定要让此账号加盟为代理吗？</div>
					<div class="footer_dialog">
						<button class="btn btn-primary" id="btn-ok">确定</button>
						<button class="btn btn-primary" id="btn-off">取消</button>
					</div>
				</div>
			</div>
		</div>
		<script type="text/javascript">
			$(function () {
				$.ajax({
                    type:"get",
                    dataType:"json",
                    url:"{:U('Admin/Main/aUserPages')}",
					success: function(datas){
						if(datas == 'error') {
						    $("#dataList").html("暂时没查询到任何数据！");
						}else{
                            options={
                                "id":"page",//显示页码的元素
                                "data":datas,//显示数据
                                "maxshowpageitem":2,//最多显示的页码个数
                                "pagelistcount":10,//每页显示数据个数
                                "callBack":function(data){
                                    var str = '';
                                    var refer = '';
                                    for(var i=0;i<data.length;i++) {
                                        if(data[i].refer == 0) {
                                            refer = '无';
                                        }else{
                                            refer = data[i].refer;
                                        }
                                        str +="<tr><td class='user_id'>"+data[i].user_id+"</td><td>"+data[i].tel+"</td><td>"+data[i].name+"</td><td>"+refer+"</td><td>"+getLocalTime(data[i].create_time)+"</td><td><button class='btn btn-primary btn-sm' onclick='onClick(this)'>通过</button>&emsp;<button class='btn btn-primary btn-sm' onclick='delClick(this)'>删除</button></td></tr>";
                                    }
                                    $("#dataList").html(str);
                                }
                            }
                            page.init(datas.length,1,options);
						}
					}
				});
            });
			function onClick(This) {
				var user_id = $(This).closest("tr").find("td.user_id").text();
				$("#bg-models").fadeIn();
				$("#bg-models .discription_dialog").html('确定要让此账号加盟为代理吗？');
				$("#btn-ok").on("click",function(){
					$("#bg-models").hide();
					$.ajax({
						type:"post",
						url:"{:U('Admin/Main/activeUser')}?user_id=" + user_id,
						success:function(data) {
							if (data == 'success') {
								window.location.href = "{:U('Admin/Main/agentUserList')}";
							} else if (data == 'error') {
								window.location.href = "{:U('Admin/Main/aUser')}";
							}
						}
					});
				});
				$("#btn-closed").on("click",function () {
					$("#bg-models").hide();
				});
				$("#btn-off").on("click",function () {
					$("#bg-models").hide();
				});
			}

			function delClick(This){
				var user_id = $(This).closest("tr").find("td.user_id").text();
				$("#bg-models").fadeIn();
				$("#bg-models .discription_dialog").html('确定要删除该加盟代理吗？');
				$("#btn-ok").on("click",function () {
					$("#bg-models").hide();
					$.ajax({
						type:"get",
						url:"{:U('Admin/Main/delUser')}?user_id=" + user_id,
						success:function(data) {
							if(data == 'success') {
								window.location.href="{:U('Admin/Main/aUser')}";
							}else if(data == 'error'){
								window.location.href="{:U('Admin/Main/aUser')}";
							}
						}
					});
				});
				$("#btn-closed").on("click",function () {
					$("#bg-models").hide();
				});
				$("#btn-off").on("click",function () {
					$("#bg-models").hide();
				})
			}
		</script>
	</body>
</html>
